# 154. 寻找旋转排序数组中的最小值 II
var findMin = function(nums) {
if (nums.length === 1) return nums[0];
nums = [...new Set(nums)];
const length = nums.length;
if (length === 1 || nums[0] < nums[length - 1]) return nums[0];
const mid = Math.ceil(length / 2);
for (let i = 1; i < mid; i++) {
if (nums[i] < nums[i - 1]) {
return nums[i];
}
}
for (let i = mid; i < length; i++) {
if (nums[i] < nums[i - 1]) {
return nums[i];
}
}
};
console.log(findMin([2, 2, 2, 0, 1]));
console.log(findMin([1, 3, 5, 1]));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24